import { Button, Cell, Input, Popup, Radio } from "@nutui/nutui-react-taro";
import { View } from "@tarojs/components";
import { useState } from "react";
import Taro from "@tarojs/taro";
import CommonTitle from "../../../../../components/CommonTitle";

const DaySelectPop = ({ open, onClose, onConfirm }) => {
  // 最小值
  const [overdue_days__gt, setoverdue_days__gt] = useState(undefined);

  //   最大值
  const [overdue_days__lt, setoverdue_days__lt] = useState(undefined);

  const [currentType, setCurrentType] = useState("1");

  // overdue_days__gt: 2  # 大于2
  // overdue_days__lt: 5  # 小于 5
  return (
    <Popup
      visible={open}
      style={{ padding: 15 }}
      onClose={() => {
        // setShowBasic(false);
        onClose?.();
      }}
      destroyOnClose
      position="top"
    >
      <View style={{ width: "90vw" }}>
        <CommonTitle title="筛选方式选择" />

        <Radio.Group
          style={{
            marginTop: 12,
          }}
          direction="horizontal"
          value={currentType}
          onChange={(e) => {
            setoverdue_days__lt(undefined);
            setoverdue_days__gt(undefined);
            setCurrentType(e);
          }}
        >
          <Radio shape="button" value="1">
            逾期天数大于
          </Radio>

          <Radio shape="button" value="2">
            逾期天数小于
          </Radio>
        </Radio.Group>

        {currentType === "1" ? (
          <Input
            style={{
              height: "120rpx",
              borderRadius: "20rpx",
              border: "1px solid #DFE2EB",
              paddingLeft: 12,
            }}
            type="number"
            placeholder="输入逾期天数大于天数"
            onChange={(v) => {
              setoverdue_days__gt(v);
            }}
            value={overdue_days__gt}
          />
        ) : (
          <Input
            style={{
              height: "120rpx",
              borderRadius: "20rpx",
              border: "1px solid #DFE2EB",
              paddingLeft: 12,
            }}
            type="number"
            placeholder="输入逾期天数小于天数"
            onChange={(v) => {
              setoverdue_days__lt(v);
            }}
            value={overdue_days__lt}
          />
        )}

        {/* <div
          style={{
            display: "flex",
            justifyContent: "space-between",
            alignItems: "center",
          }}
        >
          <Input
            type="number"
            placeholder="输入逾期范围"
            onChange={(v) => {
              console.log("onChange", v);
              setoverdue_days__gt(v);
            }}
          />
          -
          <Input
            type="number"
            placeholder="输入逾期范围"
            onChange={(v) => {
              setoverdue_days__lt(v);
            }}
            style={{
              textAlign: "center",
            }}
          />
        </div> */}
      </View>
      <View
        style={{
          width: "90vw",
          display: "flex",
          justifyContent: "space-between",
          marginTop: 12,
        }}
      >
        <Button
          onClick={() => {
            setoverdue_days__lt(undefined);
            setoverdue_days__gt(undefined);
          }}
          style={{
            width: "45%",
          }}
        >
          重置
        </Button>

        <Button
          style={{
            width: "45%",
          }}
          type="primary"
          onClick={() => {
            // if (overdue_days__gt === 0 && overdue_days__lt === 0) {
            //   return Taro.showToast({
            //     title: "请输入正确的天数",
            //     icon: "none",
            //   });
            // }
            // // 天数应该在合理范围内
            // if (overdue_days__gt > overdue_days__lt) {
            //   return Taro.showToast({
            //     title: "请输入正确的天数",
            //     icon: "none",
            //   });
            // }
            console.log("overdue_days__gt", {
              overdue_days__gt,
              overdue_days__lt,
            });
            if (overdue_days__gt || overdue_days__lt) {
              onConfirm({
                overdue_days__gt: overdue_days__gt * 1,
                overdue_days__lt: overdue_days__lt * 1,
              });
            }
          }}
        >
          确定
        </Button>
      </View>
    </Popup>
  );
};

export default DaySelectPop;
